
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>线程和进程 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-codeblock-label/block.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-click-reveal/click_reveal.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="part-2.html" />
    
    
    <link rel="prev" href="intro.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    实验简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../../notes/log.html">
            
                <a href="../../../notes/log.html">
            
                    
                    更新日志
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">实验之前</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../pre-lab/env.html">
            
                <a href="../../pre-lab/env.html">
            
                    
                    环境部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../../pre-lab/gdb.html">
            
                <a href="../../pre-lab/gdb.html">
            
                    
                    GDB 调试方法*
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">实验指导</li>
        
        
    
        <li class="chapter " data-level="3.1" >
            
                <span>
            
                    
                    实验指导零
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../../lab-0/guide/intro.html">
            
                <a href="../../lab-0/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../../lab-0/guide/part-1.html">
            
                <a href="../../lab-0/guide/part-1.html">
            
                    
                    创建项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../../lab-0/guide/part-2.html">
            
                <a href="../../lab-0/guide/part-2.html">
            
                    
                    移除标准库依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../../lab-0/guide/part-3.html">
            
                <a href="../../lab-0/guide/part-3.html">
            
                    
                    移除运行时环境依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../../lab-0/guide/part-4.html">
            
                <a href="../../lab-0/guide/part-4.html">
            
                    
                    编译为裸机目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="../../lab-0/guide/part-5.html">
            
                <a href="../../lab-0/guide/part-5.html">
            
                    
                    生成内核镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.7" data-path="../../lab-0/guide/part-6.html">
            
                <a href="../../lab-0/guide/part-6.html">
            
                    
                    调整内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.8" data-path="../../lab-0/guide/part-7.html">
            
                <a href="../../lab-0/guide/part-7.html">
            
                    
                    重写程序入口点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.9" data-path="../../lab-0/guide/part-8.html">
            
                <a href="../../lab-0/guide/part-8.html">
            
                    
                    使用 QEMU 运行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.10" data-path="../../lab-0/guide/part-9.html">
            
                <a href="../../lab-0/guide/part-9.html">
            
                    
                    接口封装和代码整理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.11" data-path="../../lab-0/guide/summary.html">
            
                <a href="../../lab-0/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" >
            
                <span>
            
                    
                    实验指导一
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../../lab-1/guide/intro.html">
            
                <a href="../../lab-1/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../../lab-1/guide/part-1.html">
            
                <a href="../../lab-1/guide/part-1.html">
            
                    
                    什么是中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../../lab-1/guide/part-2.html">
            
                <a href="../../lab-1/guide/part-2.html">
            
                    
                    RISC-V 中的中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../../lab-1/guide/part-3.html">
            
                <a href="../../lab-1/guide/part-3.html">
            
                    
                    程序运行状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../../lab-1/guide/part-4.html">
            
                <a href="../../lab-1/guide/part-4.html">
            
                    
                    状态的保存与恢复
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../../lab-1/guide/part-5.html">
            
                <a href="../../lab-1/guide/part-5.html">
            
                    
                    进入中断处理流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../../lab-1/guide/part-6.html">
            
                <a href="../../lab-1/guide/part-6.html">
            
                    
                    时钟中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.8" data-path="../../lab-1/guide/summary.html">
            
                <a href="../../lab-1/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" >
            
                <span>
            
                    
                    实验指导二
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../../lab-2/guide/intro.html">
            
                <a href="../../lab-2/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../../lab-2/guide/part-1.html">
            
                <a href="../../lab-2/guide/part-1.html">
            
                    
                    动态内存分配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../../lab-2/guide/part-2.html">
            
                <a href="../../lab-2/guide/part-2.html">
            
                    
                    物理内存探测
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../../lab-2/guide/part-3.html">
            
                <a href="../../lab-2/guide/part-3.html">
            
                    
                    物理内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../../lab-2/guide/summary.html">
            
                <a href="../../lab-2/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" >
            
                <span>
            
                    
                    实验指导三
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="../../lab-3/guide/intro.html">
            
                <a href="../../lab-3/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="../../lab-3/guide/part-1.html">
            
                <a href="../../lab-3/guide/part-1.html">
            
                    
                    从虚拟地址到物理地址
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="../../lab-3/guide/part-2.html">
            
                <a href="../../lab-3/guide/part-2.html">
            
                    
                    修改内核
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="../../lab-3/guide/part-3.html">
            
                <a href="../../lab-3/guide/part-3.html">
            
                    
                    实现页表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="../../lab-3/guide/part-4.html">
            
                <a href="../../lab-3/guide/part-4.html">
            
                    
                    实现内核重映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="../../lab-3/guide/part-5.html">
            
                <a href="../../lab-3/guide/part-5.html">
            
                    
                    页面置换*
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.7" data-path="../../lab-3/guide/summary.html">
            
                <a href="../../lab-3/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" >
            
                <span>
            
                    
                    实验指导四
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="intro.html">
            
                <a href="intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.5.2" data-path="part-1.html">
            
                <a href="part-1.html">
            
                    
                    线程和进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.3" data-path="part-2.html">
            
                <a href="part-2.html">
            
                    
                    线程的创建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="part-3.html">
            
                <a href="part-3.html">
            
                    
                    线程的切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="part-4.html">
            
                <a href="part-4.html">
            
                    
                    线程的结束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.6" data-path="part-5.html">
            
                <a href="part-5.html">
            
                    
                    内核栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.7" data-path="part-6.html">
            
                <a href="part-6.html">
            
                    
                    线程调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.8" data-path="summary.html">
            
                <a href="summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" >
            
                <span>
            
                    
                    实验指导五
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../../lab-5/guide/intro.html">
            
                <a href="../../lab-5/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../../lab-5/guide/part-1.html">
            
                <a href="../../lab-5/guide/part-1.html">
            
                    
                    设备树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../../lab-5/guide/part-2.html">
            
                <a href="../../lab-5/guide/part-2.html">
            
                    
                    virtio
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.4" data-path="../../lab-5/guide/part-3.html">
            
                <a href="../../lab-5/guide/part-3.html">
            
                    
                    驱动和块设备驱动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.5" data-path="../../lab-5/guide/part-4.html">
            
                <a href="../../lab-5/guide/part-4.html">
            
                    
                    文件系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.6" data-path="../../lab-5/guide/summary.html">
            
                <a href="../../lab-5/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" >
            
                <span>
            
                    
                    实验指导六
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="../../lab-6/guide/intro.html">
            
                <a href="../../lab-6/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="../../lab-6/guide/part-1.html">
            
                <a href="../../lab-6/guide/part-1.html">
            
                    
                    构建用户程序框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.3" data-path="../../lab-6/guide/part-2.html">
            
                <a href="../../lab-6/guide/part-2.html">
            
                    
                    打包为磁盘镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.4" data-path="../../lab-6/guide/part-3.html">
            
                <a href="../../lab-6/guide/part-3.html">
            
                    
                    解析 ELF 文件并创建线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.5" data-path="../../lab-6/guide/part-4.html">
            
                <a href="../../lab-6/guide/part-4.html">
            
                    
                    实现系统调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.6" data-path="../../lab-6/guide/part-5.html">
            
                <a href="../../lab-6/guide/part-5.html">
            
                    
                    处理文件描述符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.7" data-path="../../lab-6/guide/part-6.html">
            
                <a href="../../lab-6/guide/part-6.html">
            
                    
                    条件变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.8" data-path="../../lab-6/guide/summary.html">
            
                <a href="../../lab-6/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">实验题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../lab-1/practice.html">
            
                <a href="../../lab-1/practice.html">
            
                    
                    实验一：中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../../lab-2/practice.html">
            
                <a href="../../lab-2/practice.html">
            
                    
                    实验二：内存分配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../../lab-3/practice.html">
            
                <a href="../../lab-3/practice.html">
            
                    
                    实验三：虚实地址转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../practice-1.html">
            
                <a href="../practice-1.html">
            
                    
                    实验四（上）：线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../practice-2.html">
            
                <a href="../practice-2.html">
            
                    
                    实验四（下）：线程调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../../lab-6/practice.html">
            
                <a href="../../lab-6/practice.html">
            
                    
                    实验六：系统调用
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">开发笔记</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../format/partition.html">
            
                <a href="../../format/partition.html">
            
                    
                    文档代码划分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../../format/doc.html">
            
                <a href="../../format/doc.html">
            
                    
                    文档格式规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../../format/code.html">
            
                <a href="../../format/code.html">
            
                    
                    代码格式规范
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >线程和进程</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x7EBF;&#x7A0B;&#x548C;&#x8FDB;&#x7A0B;">&#x7EBF;&#x7A0B;&#x548C;&#x8FDB;&#x7A0B;</h2>
<h3 id="&#x57FA;&#x672C;&#x6982;&#x5FF5;">&#x57FA;&#x672C;&#x6982;&#x5FF5;</h3>
<p>&#x4ECE;<strong>&#x6E90;&#x4EE3;&#x7801;</strong>&#x7ECF;&#x8FC7;&#x7F16;&#x8BD1;&#x5668;&#x4E00;&#x7CFB;&#x5217;&#x5904;&#x7406;&#xFF08;&#x7F16;&#x8BD1;&#x3001;&#x94FE;&#x63A5;&#x3001;&#x4F18;&#x5316;&#x7B49;&#xFF09;&#x5F97;&#x5230;&#x7684;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x79F0;&#x4E3A;<strong>&#x7A0B;&#x5E8F;&#xFF08;Program&#xFF09;</strong>&#x3002;&#x800C;&#x901A;&#x4FD7;&#x5730;&#x8BF4;&#xFF0C;<strong>&#x8FDB;&#x7A0B;&#xFF08;Process&#xFF09;</strong>&#x5C31;&#x662F;<strong>&#x6B63;&#x5728;&#x8FD0;&#x884C;</strong>&#x5E76;<strong>&#x4F7F;&#x7528;&#x8BA1;&#x7B97;&#x673A;&#x8D44;&#x6E90;</strong>&#x7684;&#x7A0B;&#x5E8F;&#xFF0C;&#x4E0E;&#x653E;&#x5728;&#x78C1;&#x76D8;&#x4E2D;&#x4E00;&#x52A8;&#x4E0D;&#x52A8;&#x7684;&#x7A0B;&#x5E8F;&#x4E0D;&#x540C;&#xFF1A;&#x9996;&#x5148;&#xFF0C;&#x8FDB;&#x7A0B;&#x5F97;&#x5230;&#x4E86;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x63D0;&#x4F9B;&#x7684;<strong>&#x8D44;&#x6E90;</strong>&#xFF1A;&#x7A0B;&#x5E8F;&#x7684;&#x4EE3;&#x7801;&#x3001;&#x6570;&#x636E;&#x6BB5;&#x88AB;&#x52A0;&#x8F7D;&#x5230;<strong>&#x5185;&#x5B58;</strong>&#x4E2D;&#xFF0C;&#x7A0B;&#x5E8F;&#x6240;&#x9700;&#x7684;&#x865A;&#x62DF;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x88AB;&#x771F;&#x6B63;&#x6784;&#x5EFA;&#x51FA;&#x6765;&#x3002;&#x540C;&#x65F6;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x8FD8;&#x7ED9;&#x8FDB;&#x7A0B;&#x5206;&#x914D;&#x4E86;&#x7A0B;&#x5E8F;&#x6240;&#x8981;&#x6C42;&#x7684;&#x5404;&#x79CD;<strong>&#x5176;&#x4ED6;&#x8D44;&#x6E90;</strong>&#xFF0C;&#x5982;&#x6211;&#x4EEC;&#x4E0A;&#x9762;&#x51E0;&#x4E2A;&#x7AE0;&#x8282;&#x4E2D;&#x63D0;&#x5230;&#x8FC7;&#x7684;&#x9875;&#x8868;&#x3001;&#x6587;&#x4EF6;&#x7684;&#x8D44;&#x6E90;&#x3002;</p>
<p>&#x7136;&#x800C;&#x5982;&#x679C;&#x4EC5;&#x6B64;&#x800C;&#x5DF2;&#xFF0C;&#x8FDB;&#x7A0B;&#x8FD8;&#x5C1A;&#x672A;&#x4F53;&#x73B0;&#x51FA;&#x5176;&#x201C;<strong>&#x6B63;&#x5728;&#x8FD0;&#x884C;</strong>&#x201D;&#x7684;&#x52A8;&#x6001;&#x7279;&#x6027;&#x3002;&#x800C;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x610F;&#x5473;&#x7740; <strong>CPU</strong> &#x8981;&#x53BB;&#x6267;&#x884C;&#x7A0B;&#x5E8F;&#x4EE3;&#x7801;&#x6BB5;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x4E3A;&#x4E86;&#x80FD;&#x591F;&#x8FDB;&#x884C;&#x51FD;&#x6570;&#x8C03;&#x7528;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x9700;&#x8981;<strong>&#x8FD0;&#x884C;&#x6808;&#xFF08;Stack&#xFF09;</strong>&#x3002;</p>
<p>&#x51FA;&#x4E8E;OS&#x5BF9;&#x8BA1;&#x7B97;&#x673A;&#x7CFB;&#x7EDF;&#x7CBE;&#x7EC6;&#x7BA1;&#x7406;&#x7684;&#x76EE;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x5C06;&#x201C;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x201D;&#x7684;&#x52A8;&#x6001;&#x7279;&#x6027;&#x4ECE;&#x8FDB;&#x7A0B;&#x4E2D;&#x5265;&#x79BB;&#x51FA;&#x6765;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x4E00;&#x4E2A;&#x501F;&#x52A9; CPU &#x548C;&#x6808;&#x7684;&#x6267;&#x884C;&#x6D41;&#xFF0C;&#x6211;&#x4EEC;&#x79F0;&#x4E4B;&#x4E3A;<strong>&#x7EBF;&#x7A0B; (Thread)</strong> &#x3002;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x53EF;&#x4EE5;&#x6709;&#x591A;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5982;&#x4F20;&#x7EDF;&#x8FDB;&#x7A0B;&#x4E00;&#x6837;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#xFF0C;&#x8FDB;&#x7A0B;&#x867D;&#x7136;&#x4ECD;&#x662F;&#x4EE3;&#x8868;&#x4E00;&#x4E2A;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x7A0B;&#x5E8F;&#xFF0C;&#x4F46;&#x662F;&#x5176;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x4F5C;&#x4E3A;<strong>&#x8D44;&#x6E90;&#x7684;&#x5206;&#x914D;&#x5355;&#x4F4D;</strong>&#xFF0C;&#x7BA1;&#x7406;&#x9875;&#x8868;&#x3001;&#x6587;&#x4EF6;&#x3001;&#x7F51;&#x7EDC;&#x7B49;&#x8D44;&#x6E90;&#x3002;&#x800C;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x7684;&#x591A;&#x4E2A;&#x7EBF;&#x7A0B;&#x5219;&#x5171;&#x4EAB;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#xFF0C;&#x4E13;&#x6CE8;&#x4E8E;&#x6267;&#x884C;&#xFF0C;&#x4ECE;&#x800C;&#x4F5C;&#x4E3A;<strong>&#x6267;&#x884C;&#x7684;&#x8C03;&#x5EA6;&#x5355;&#x4F4D;</strong>&#x3002;&#x4E3E;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x4E3A;&#x4E86;&#x5206;&#x914D;&#x7ED9;&#x8FDB;&#x7A0B;&#x4E00;&#x6BB5;&#x5185;&#x5B58;&#xFF0C;&#x6211;&#x4EEC;&#x628A;&#x4E00;&#x6574;&#x4E2A;&#x9875;&#x8868;&#x4EA4;&#x7ED9;&#x8FDB;&#x7A0B;&#xFF0C;&#x800C;&#x51FA;&#x4E8E;&#x67D0;&#x4E9B;&#x76EE;&#x7684;&#xFF08;&#x6BD4;&#x5982;&#x4E3A;&#x4E86;&#x52A0;&#x901F;&#x9700;&#x8981;&#x4E24;&#x4E2A;&#x7EBF;&#x7A0B;&#x653E;&#x5728;&#x4E24;&#x4E2A; CPU &#x7684;&#x6838;&#x4E0A;&#xFF09;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x7EBF;&#x7A0B;&#x7684;&#x6982;&#x5FF5;&#x6765;&#x8FDB;&#x4E00;&#x6B65;&#x7EC6;&#x5316;&#x6267;&#x884C;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x8FD9;&#x65F6;&#x8FDB;&#x7A0B;&#x5185;&#x90E8;&#x7684;&#x5168;&#x90E8;&#x8FD9;&#x4E9B;&#x7EBF;&#x7A0B;&#x770B;&#x5230;&#x7684;&#x5C31;&#x662F;&#x540C;&#x6837;&#x7684;&#x9875;&#x8868;&#xFF0C;&#x770B;&#x5230;&#x7684;&#x4E5F;&#x662F;&#x76F8;&#x540C;&#x7684;&#x5730;&#x5740;&#x3002;&#x4F46;&#x662F;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x8FD9;&#x4E9B;&#x7EBF;&#x7A0B;&#x4E3A;&#x4E86;&#x53EF;&#x4EE5;&#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#xFF0C;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x6808;&#xFF08;&#x4F1A;&#x653E;&#x5728;&#x76F8;&#x540C;&#x5730;&#x5740;&#x7A7A;&#x95F4;&#x7684;&#x4E0D;&#x540C;&#x4F4D;&#x7F6E;&#xFF09;&#xFF0C;CPU &#x4E5F;&#x4F1A;&#x4EE5;&#x5B83;&#x4EEC;&#x8FD9;&#x4E9B;&#x7EBF;&#x7A0B;&#x4E3A;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x8C03;&#x5EA6;&#x5355;&#x4F4D;&#x3002;</p>
<h3 id="&#x7EBF;&#x7A0B;&#x7684;&#x8868;&#x793A;">&#x7EBF;&#x7A0B;&#x7684;&#x8868;&#x793A;</h3>
<p>&#x5728;&#x4E0D;&#x540C;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E2D;&#xFF0C;&#x4E3A;&#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x6240;&#x4FDD;&#x5B58;&#x7684;&#x4FE1;&#x606F;&#x90FD;&#x4E0D;&#x540C;&#x3002;&#x5728;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E00;&#x79CD;&#x57FA;&#x7840;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x4F1A;&#x5305;&#x62EC;&#xFF1A;</p>
<ul>
<li><strong>&#x7EBF;&#x7A0B; ID</strong>&#xFF1A;&#x7528;&#x4E8E;&#x552F;&#x4E00;&#x786E;&#x8BA4;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x5B83;&#x4F1A;&#x5728;&#x7CFB;&#x7EDF;&#x8C03;&#x7528;&#x7B49;&#x65F6;&#x523B;&#x7528;&#x5230;&#x3002;</li>
<li><strong>&#x8FD0;&#x884C;&#x6808;</strong>&#xFF1A;&#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x90FD;&#x5FC5;&#x987B;&#x6709;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x8FD0;&#x884C;&#x6808;&#xFF0C;&#x4FDD;&#x5B58;&#x8FD0;&#x884C;&#x65F6;&#x6570;&#x636E;&#x3002;</li>
<li><strong>&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x4E0A;&#x4E0B;&#x6587;</strong>&#xFF1A;&#x5F53;&#x7EBF;&#x7A0B;&#x4E0D;&#x5728;&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4FDD;&#x5B58;&#x5176;&#x4E0A;&#x4E0B;&#x6587;&#xFF08;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4E00;&#x5806;<strong>&#x5BC4;&#x5B58;&#x5668;</strong>&#x7684;&#x503C;&#xFF09;&#xFF0C;&#x8FD9;&#x6837;&#x4E4B;&#x540E;&#x624D;&#x80FD;&#x591F;&#x5C06;&#x5176;&#x6062;&#x590D;&#xFF0C;&#x7EE7;&#x7EED;&#x8FD0;&#x884C;&#x3002;&#x548C;&#x4E4B;&#x524D;&#x5B9E;&#x73B0;&#x7684;&#x4E2D;&#x65AD;&#x4E00;&#x6837;&#xFF0C;&#x4E0A;&#x4E0B;&#x6587;&#x7531; <code>Context</code> &#x7C7B;&#x578B;&#x4FDD;&#x5B58;&#x3002;&#xFF08;&#x6CE8;&#xFF1A;&#x8FD9;&#x91CC;&#x7684;<strong>&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x4E0A;&#x4E0B;&#x6587;</strong>&#x4E0E;&#x524D;&#x9762;&#x63D0;&#x5230;&#x7684;<strong>&#x4E2D;&#x65AD;&#x4E0A;&#x4E0B;&#x6587;</strong>&#x662F;&#x4E0D;&#x540C;&#x7684;&#x6982;&#x5FF5;&#xFF09;</li>
<li><strong>&#x6240;&#x5C5E;&#x8FDB;&#x7A0B;&#x7684;&#x8BB0;&#x53F7;</strong>&#xFF1A;&#x540C;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x4E2D;&#x7684;&#x591A;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x4F1A;&#x5171;&#x4EAB;&#x9875;&#x8868;&#x3001;&#x6253;&#x5F00;&#x6587;&#x4EF6;&#x7B49;&#x4FE1;&#x606F;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5B83;&#x4EEC;&#x63D0;&#x53D6;&#x51FA;&#x6765;&#x653E;&#x5230;&#x7EBF;&#x7A0B;&#x4E2D;&#x3002;</li>
<li><strong><em>&#x5185;&#x6838;&#x6808;</em></strong>&#xFF1A;&#x9664;&#x4E86;&#x7EBF;&#x7A0B;&#x8FD0;&#x884C;&#x5FC5;&#x987B;&#x6709;&#x7684;&#x8FD0;&#x884C;&#x6808;&#xFF0C;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x4E5F;&#x5FC5;&#x987B;&#x6709;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x6808;&#x3002;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x662F;&#x76F4;&#x63A5;&#x5728;&#x539F;&#x6765;&#x7684;&#x6808;&#x4E0A;&#x8FDB;&#x884C;&#xFF08;&#x6211;&#x4EEC;&#x76F4;&#x63A5;&#x5C06; <code>Context</code> &#x538B;&#x5165;&#x6808;&#xFF09;&#x3002;&#x4F46;&#x662F;&#x5728;&#x540E;&#x9762;&#x6211;&#x4EEC;&#x4F1A;&#x5F15;&#x5165;&#x7528;&#x6237;&#x7EBF;&#x7A0B;&#xFF0C;&#x8FD9;&#x65F6;&#x5C31;&#x53EA;&#x6709;&#x4E0A;&#x5E1D;&#x624D;&#x77E5;&#x9053;&#x53D1;&#x751F;&#x4E86;&#x4EC0;&#x4E48;&#x2014;&#x2014;&#x6808;&#x6307;&#x9488;&#x3001;&#x7A0B;&#x5E8F;&#x6307;&#x9488;&#x90FD;&#x53EF;&#x80FD;&#x5728;&#x8DE8;&#x56FD;&#xFF08;<strong>&#x56FD; == &#x7279;&#x6743;&#x6001;</strong>&#xFF09;&#x65C5;&#x6E38;&#x3002;&#x4E3A;&#x4E86;&#x786E;&#x4FDD;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x80FD;&#x591F;&#x8FDB;&#x884C;&#xFF08;&#x8BA9;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x80FD;&#x591F;&#x63A5;&#x7BA1;&#x8FD9;&#x6837;&#x7684;&#x7EBF;&#x7A0B;&#xFF09;&#xFF0C;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x5FC5;&#x987B;&#x8FD0;&#x884C;&#x5728;&#x4E00;&#x4E2A;&#x51C6;&#x5907;&#x597D;&#x7684;&#x3001;&#x5B89;&#x5168;&#x7684;&#x6808;&#x4E0A;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x5185;&#x6838;&#x6808;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x5185;&#x6838;&#x6808;&#x5E76;&#x6CA1;&#x6709;&#x5B58;&#x50A8;&#x5728;&#x7EBF;&#x7A0B;&#x4FE1;&#x606F;&#x4E2D;&#x3002;&#xFF08;&#x6CE8;&#xFF1A;<strong>&#x5B83;&#x7684;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4F1A;&#x6709;&#x4E9B;&#x590D;&#x6742;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5728;&#x540E;&#x9762;&#x8BB2;&#x89E3;</strong>&#x3002;&#xFF09;</li>
</ul>
<p></p><p class="code-label">os/src/process/thread.rs</p><p></p>
<pre><code class="lang-rust"><span class="hljs-comment">/// &#x7EBF;&#x7A0B;&#x7684;&#x4FE1;&#x606F;</span>
<span class="hljs-keyword">pub</span> <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Thread</span></span> {
    <span class="hljs-comment">/// &#x7EBF;&#x7A0B; ID</span>
    <span class="hljs-keyword">pub</span> id: ThreadID,
    <span class="hljs-comment">/// &#x7EBF;&#x7A0B;&#x7684;&#x6808;</span>
    <span class="hljs-keyword">pub</span> stack: Range&lt;VirtualAddress&gt;,
    <span class="hljs-comment">/// &#x6240;&#x5C5E;&#x7684;&#x8FDB;&#x7A0B;</span>
    <span class="hljs-keyword">pub</span> process: Arc&lt;Process&gt;,
    <span class="hljs-comment">/// &#x7528; `Mutex` &#x5305;&#x88C5;&#x4E00;&#x4E9B;&#x53EF;&#x53D8;&#x7684;&#x53D8;&#x91CF;</span>
    <span class="hljs-keyword">pub</span> inner: Mutex&lt;ThreadInner&gt;,
}

<span class="hljs-comment">/// &#x7EBF;&#x7A0B;&#x4E2D;&#x9700;&#x8981;&#x53EF;&#x53D8;&#x7684;&#x90E8;&#x5206;</span>
<span class="hljs-keyword">pub</span> <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">ThreadInner</span></span> {
    <span class="hljs-comment">/// &#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x4E0A;&#x4E0B;&#x6587;</span>
    <span class="hljs-comment">///</span>
    <span class="hljs-comment">/// &#x5F53;&#x4E14;&#x4EC5;&#x5F53;&#x7EBF;&#x7A0B;&#x88AB;&#x6682;&#x505C;&#x6267;&#x884C;&#x65F6;&#xFF0C;`context` &#x4E3A; `Some`</span>
    <span class="hljs-keyword">pub</span> context: <span class="hljs-built_in">Option</span>&lt;Context&gt;,
    <span class="hljs-comment">/// &#x662F;&#x5426;&#x8FDB;&#x5165;&#x4F11;&#x7720;</span>
    <span class="hljs-keyword">pub</span> sleeping: <span class="hljs-keyword">bool</span>,
    <span class="hljs-comment">/// &#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x7ED3;&#x675F;</span>
    <span class="hljs-keyword">pub</span> dead: <span class="hljs-keyword">bool</span>,
}
</code></pre>
<p>&#x6CE8;&#x610F;&#x5230;&#xFF0C;&#x56E0;&#x4E3A;&#x7EBF;&#x7A0B;&#x4E00;&#x822C;&#x4F7F;&#x7528; <code>Arc&lt;Thread&gt;</code> &#x6765;&#x4FDD;&#x5B58;&#xFF0C;&#x5B83;&#x662F;&#x4E0D;&#x53EF;&#x53D8;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x5176;&#x4E2D;&#x518D;&#x7528; <code>Mutex</code> &#x6765;&#x5305;&#x88C5;&#x4E00;&#x90E8;&#x5206;&#xFF0C;&#x8BA9;&#x8FD9;&#x90E8;&#x5206;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x3002;</p>
<h3 id="&#x8FDB;&#x7A0B;&#x7684;&#x8868;&#x793A;">&#x8FDB;&#x7A0B;&#x7684;&#x8868;&#x793A;</h3>
<p>&#x5728;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;&#x7684;&#x7B80;&#x5355;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E2D;&#xFF0C;&#x8FDB;&#x7A0B;&#x53EA;&#x9700;&#x8981;&#x7EF4;&#x62A4;&#x9875;&#x9762;&#x6620;&#x5C04;&#xFF0C;&#x5E76;&#x4E14;&#x5B58;&#x50A8;&#x4E00;&#x70B9;&#x989D;&#x5916;&#x4FE1;&#x606F;&#xFF1A;</p>
<ul>
<li><strong>&#x7528;&#x6237;&#x6001;&#x6807;&#x8BC6;</strong>&#xFF1A;&#x6211;&#x4EEC;&#x4F1A;&#x5728;&#x540E;&#x9762;&#x8FDB;&#x884C;&#x533A;&#x5206;&#x5185;&#x6838;&#x6001;&#x7EBF;&#x7A0B;&#x548C;&#x7528;&#x6237;&#x6001;&#x7EBF;&#x7A0B;&#x3002;</li>
<li><strong>&#x8BBF;&#x5B58;&#x7A7A;&#x95F4; <code>MemorySet</code></strong>&#xFF1A;&#x8FDB;&#x7A0B;&#x4E2D;&#x7684;&#x7EBF;&#x7A0B;&#x4F1A;&#x5171;&#x4EAB;&#x540C;&#x4E00;&#x4E2A;&#x9875;&#x8868;&#xFF0C;&#x5373;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x7684;&#x865A;&#x62DF;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#xFF08;&#x7B80;&#x79F0;&#xFF1A;&#x8BBF;&#x5B58;&#x7A7A;&#x95F4;&#xFF09;&#x3002;</li>
</ul>
<p></p><p class="code-label">os/src/process/process.rs</p><p></p>
<pre><code class="lang-rust"><span class="hljs-comment">/// &#x8FDB;&#x7A0B;&#x7684;&#x4FE1;&#x606F;</span>
<span class="hljs-keyword">pub</span> <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Process</span></span> {
    <span class="hljs-comment">/// &#x662F;&#x5426;&#x5C5E;&#x4E8E;&#x7528;&#x6237;&#x6001;</span>
    <span class="hljs-keyword">pub</span> is_user: <span class="hljs-keyword">bool</span>,
    <span class="hljs-comment">/// &#x7528; `Mutex` &#x5305;&#x88C5;&#x4E00;&#x4E9B;&#x53EF;&#x53D8;&#x7684;&#x53D8;&#x91CF;</span>
    <span class="hljs-keyword">pub</span> inner: Mutex&lt;ProcessInner&gt;,
}

<span class="hljs-keyword">pub</span> <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">ProcessInner</span></span> {
    <span class="hljs-comment">/// &#x8FDB;&#x7A0B;&#x4E2D;&#x7684;&#x7EBF;&#x7A0B;&#x516C;&#x7528;&#x9875;&#x8868; / &#x5185;&#x5B58;&#x6620;&#x5C04;</span>
    <span class="hljs-keyword">pub</span> memory_set: MemorySet,
<span class="hljs-comment">//  /// &#x6253;&#x5F00;&#x7684;&#x6587;&#x4EF6;&#x63CF;&#x8FF0;&#x7B26;&#xFF08;&#x5B9E;&#x9A8C;&#x4E94;&#xFF09;</span>
<span class="hljs-comment">//  pub descriptors: Vec&lt;Arc&lt;dyn INode&gt;&gt;,</span>
}
</code></pre>
<p>&#x540C;&#x6837;&#x5730;&#xFF0C;&#x7EBF;&#x7A0B;&#x4E5F;&#x9700;&#x8981;&#x4E00;&#x90E8;&#x5206;&#x662F;&#x53EF;&#x53D8;&#x7684;&#x3002;</p>
<h3 id="&#x5904;&#x7406;&#x5668;">&#x5904;&#x7406;&#x5668;</h3>
<p>&#x6709;&#x4E86;&#x7EBF;&#x7A0B;&#x548C;&#x8FDB;&#x7A0B;&#xFF0C;&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x518D;&#x62BD;&#x8C61;&#x51FA;&#x300C;&#x5904;&#x7406;&#x5668;&#x300D;&#x6765;&#x5B58;&#x653E;&#x548C;&#x7BA1;&#x7406;&#x7EBF;&#x7A0B;&#x6C60;&#x3002;&#x540C;&#x65F6;&#xFF0C;&#x4E5F;&#x9700;&#x8981;&#x5B58;&#x653E;&#x548C;&#x7BA1;&#x7406;&#x76EE;&#x524D;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#xFF08;&#x5373;&#x4E2D;&#x65AD;&#x524D;&#x6267;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x56E0;&#x4E3A;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x5728;&#x5DE5;&#x4F5C;&#x65F6;&#x662F;&#x5904;&#x4E8E;&#x4E2D;&#x65AD;&#x3001;&#x5F02;&#x5E38;&#x6216;&#x7CFB;&#x7EDF;&#x8C03;&#x7528;&#x670D;&#x52A1;&#x4E4B;&#x4E2D;&#xFF09;&#x3002;</p>
<p></p><p class="code-label">os/src/process/processor.rs</p><p></p>
<pre><code class="lang-rust"><span class="hljs-comment">/// &#x7EBF;&#x7A0B;&#x8C03;&#x5EA6;&#x548C;&#x7BA1;&#x7406;</span>
<span class="hljs-comment">///</span>
<span class="hljs-comment">/// &#x4F11;&#x7720;&#x7EBF;&#x7A0B;&#x4F1A;&#x4ECE;&#x8C03;&#x5EA6;&#x5668;&#x4E2D;&#x79FB;&#x9664;&#xFF0C;&#x5355;&#x72EC;&#x4FDD;&#x5B58;&#x3002;&#x5728;&#x5B83;&#x4EEC;&#x88AB;&#x5524;&#x9192;&#x4E4B;&#x524D;&#xFF0C;&#x4E0D;&#x4F1A;&#x88AB;&#x8C03;&#x5EA6;&#x5668;&#x5B89;&#x6392;&#x3002;</span>
<span class="hljs-keyword">pub</span> <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Processor</span></span> {
    <span class="hljs-comment">/// &#x5F53;&#x524D;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x7EBF;&#x7A0B;</span>
    current_thread: <span class="hljs-built_in">Option</span>&lt;Arc&lt;Thread&gt;&gt;,
    <span class="hljs-comment">/// &#x7EBF;&#x7A0B;&#x8C03;&#x5EA6;&#x5668;&#xFF0C;&#x8BB0;&#x5F55;&#x6D3B;&#x8DC3;&#x7EBF;&#x7A0B;</span>
    scheduler: SchedulerImpl&lt;Arc&lt;Thread&gt;&gt;,
    <span class="hljs-comment">/// &#x4FDD;&#x5B58;&#x4F11;&#x7720;&#x7EBF;&#x7A0B;</span>
    sleeping_threads: HashSet&lt;Arc&lt;Thread&gt;&gt;,
}
</code></pre>
<ul>
<li><code>current_thread</code> &#x9700;&#x8981;&#x4FDD;&#x5B58;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x8FD9;&#x6837;&#x5F53;&#x51FA;&#x73B0;&#x7CFB;&#x7EDF;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4FBF;&#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x5730;&#x77E5;&#x9053;&#x662F;&#x54EA;&#x4E2A;&#x7EBF;&#x7A0B;&#x5728;&#x4E3E;&#x624B;&#x3002;</li>
<li><code>scheduler</code> &#x4F1A;&#x8D1F;&#x8D23;&#x8C03;&#x5EA6;&#x7EBF;&#x7A0B;&#xFF0C;&#x5176;&#x63A5;&#x53E3;&#x5C31;&#x662F;&#x7B80;&#x5355;&#x7684;&#x201C;&#x6DFB;&#x52A0;&#x201D;&#x201C;&#x79FB;&#x9664;&#x201D;&#x201C;&#x83B7;&#x53D6;&#x4E0B;&#x4E00;&#x4E2A;&#x201D;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5728;<a href="part-6.html">&#x540E;&#x9762;</a>&#x8BE6;&#x7EC6;&#x8BB2;&#x5230;&#x3002;</li>
<li>&#x4F11;&#x7720;&#x7EBF;&#x7A0B;&#x662F;&#x6307;&#x7B49;&#x5F85;&#x4E00;&#x4E9B;&#x5916;&#x90E8;&#x8D44;&#x6E90;&#xFF08;&#x4F8B;&#x5982;&#x786C;&#x76D8;&#x8BFB;&#x53D6;&#x3001;&#x5916;&#x8BBE;&#x8BFB;&#x53D6;&#x7B49;&#xFF09;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x8FD9;&#x65F6; CPU &#x5982;&#x679C;&#x7ED9;&#x5176;&#x65F6;&#x95F4;&#x7247;&#x8FD0;&#x884C;&#x662F;&#x6CA1;&#x6709;&#x610F;&#x4E49;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x5B83;&#x4EEC;&#x4E5F;&#x5C31;&#x9700;&#x8981;&#x79FB;&#x51FA;&#x8C03;&#x5EA6;&#x5668;&#x800C;&#x5355;&#x72EC;&#x4FDD;&#x5B58;&#x3002;</li>
</ul>
<p></p><p class="code-label">os/src/process/processor.rs</p><p></p>
<pre><code class="lang-rust">lazy_static! {
    <span class="hljs-comment">/// &#x5168;&#x5C40;&#x7684; [`Processor`]</span>
    <span class="hljs-keyword">pub</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">ref</span> PROCESSOR: Lock&lt;Processor&gt; = Lock::new(Processor::default());
}
</code></pre>
<p>&#x6CE8;&#x610F;&#x5230;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x7528;&#x4E86;&#x4E00;&#x4E2A; <code>Lock</code>&#xFF08;<code>os/process/lock.rs</code>&#xFF09;&#xFF0C;&#x5B83;&#x5C01;&#x88C5;&#x4E86; <code>spin::Mutex</code>&#xFF0C;&#x800C;&#x5728;&#x5176;&#x57FA;&#x7840;&#x4E0A;&#x8FDB;&#x4E00;&#x6B65;&#x5173;&#x95ED;&#x4E86;&#x4E2D;&#x65AD;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#xFF08;&#x4EE5;&#x540E;&#xFF09;&#x5728;&#x5185;&#x6838;&#x7EBF;&#x7A0B;&#x4E2D;&#x4E5F;&#x6709;&#x53EF;&#x80FD;&#x8BBF;&#x95EE; <code>PROCESSOR</code>&#xFF0C;&#x4F46;&#x662F;&#x6B64;&#x65F6;&#x6211;&#x4EEC;&#x4E0D;&#x5E0C;&#x671B;&#x5B83;&#x88AB;&#x65F6;&#x949F;&#x6253;&#x65AD;&#xFF0C;&#x8FD9;&#x6837;&#x5728;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x4E2D;&#x5C31;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE; <code>PROCESSOR</code> &#x4E86;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5DF2;&#x7ECF;&#x88AB;&#x9501;&#x4F4F;&#x3002;</p>
<p><div id="page-footer" class="localized-footer"><hr><p><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"></p>
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script>
    var gitalk = new Gitalk({
        clientID: "5084c46751a4b2f7cd4d",
        clientSecret: "3904f62d33aef24f19480fedc836a48b31d532e9",
        repo: "rCore-Tutorial-deploy",
        owner: "rcore-os",
        admin: [
            "chyyuu",
            "wangrunji0408",
            "xy-plus",
            "wyfcyx",
            "LyricZhao",
            "Tuyixiang"
        ],
        id: location.pathname.replace('/rCore-Tutorial-deploy', '').replace('.html', ''),
        distractionFreeMode: false
    });
    gitalk.render("gitalk-container");
</script></div></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="intro.html" class="navigation navigation-prev " aria-label="Previous page: 摘要">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="part-2.html" class="navigation navigation-next " aria-label="Next page: 线程的创建">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"线程和进程","level":"3.5.2","depth":2,"next":{"title":"线程的创建","level":"3.5.3","depth":2,"path":"docs/lab-4/guide/part-2.md","ref":"docs/lab-4/guide/part-2.md","articles":[]},"previous":{"title":"摘要","level":"3.5.1","depth":2,"path":"docs/lab-4/guide/intro.md","ref":"docs/lab-4/guide/intro.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["hide-element","chapter-fold","katex","alerts","emphasize","mermaid-gb3","codeblock-label","code","search-pro","click-reveal","expandable-chapters-interactive","localized-footer"],"pluginsConfig":{"chapter-fold":{},"emphasize":{},"codeblock-label":{},"search-pro":{},"search":{},"localized-footer":{"filename":"gitalk.html","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"hide-element":{},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":1},"click-reveal":{},"highlight":{},"mermaid-gb3":{},"expandable-chapters-interactive":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"docs/lab-4/guide/part-1.md","mtime":"2020-10-01T11:39:40.515Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-01T11:40:38.595Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-click-reveal/click_reveal.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

